<?php

/**
 * photo actions.
 *
 * @package    sfwixet
 * @subpackage photo
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class profilePhotosComponents extends sfComponents
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  		$photos = array();
  		$photoQuery = Doctrine_Manager::getInstance()
  			->getCurrentConnection()
  			->fetchAssoc("(select owner_id,photo_id,last_activity from photo where owner_id = ?)
union
(select owner_id,photo_id,last_activity from photo_tag
join photo using(photo_id) where user_id = ?)
order by last_activity DESC
LIMIT 10",array($request->getParameter("id",$this->getUser()->getId()),$request->getParameter("id",$this->getUser()->getId())));
//LIMIT 50");
  			//We only want 10 photos (more or less) but it we try to load a forbidden photo we
  			//only show 10-forbidden photos. Because of that we get 50 in the initial query to
  			//have a margin of 40.
  			//TODO if there are more than 40 forbbiden photos get more photos
  			//ej: using offset and a counter to count the gotten or forbidden photos
  		foreach($photoQuery as $photoId){
  			try{
  				$photo = Doctrine::getTable("Photo")->find($photoId['photo_id']);
  				$photos[] = $photo;		
  			}catch(Exception $e){
  				//forbidden photo!
  			}
  			$this->photos = $photos;
  		}

  }
  
  public function executeTitle(sfWebRequest $request)
  {

  }
}
